# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-ast
pkgver=2.4.2
pkgrel=2
pkgdesc='A library for working with Abstract Syntax Trees'
arch=(any)
url='https://whitequark.github.io/ast/'
license=(MIT)
depends=(ruby)
checkdepends=(ruby-rake ruby-bacon ruby-bacon-colored_output ruby-simplecov ruby-yard ruby-kramdown)
options=(!emptydirs)
source=(https://github.com/whitequark/ast/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('e3fbf580fb2139b0c0751594ba660ecb222de3786486355d59254b8ff424036f')

prepare() {
  cd ast-$pkgver
  sed -r -e '/[cC]overalls/d' -e 's|~>|>=|g' -i ast.gemspec test/helper.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd ast-$pkgver
  gem build ast.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    ast-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd ast-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake test
}

package() {
  cd ast-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.MIT -t "$pkgdir"/usr/share/licenses/$pkgname/
}
